<?php

namespace app\admin\model;

use think\Model;

//用户积分表
class Score extends Model
{

    

    

    // 表名
    protected $name = 'score';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'change_type_text',
        'seq_flag_text',
        'change_time_text'
    ];
    

    
    public function getChangeTypeList()
    {
        return [
            '1' => __('Change_type 1'),
            '2' => __('Change_type 2'),
            '3' => __('Change_type 3'),
            '4' => __('Change_type 4'),
            '5' => __('Change_type 5'),
            '6' => __('Change_type 6'),
            '7' => __('Change_type 7'),
            '8' => __('Change_type 8'),
            '9' => __('Change_type 9'),
            '10' => __('Change_type 10'),
            '11' => __('Change_type 11'),
            '12' => __('Change_type 12'),
            '13' => __('Change_type 13'),
        ];
    }

    public function getSeqFlagList()
    {
        return ['1' => __('Seq_flag 1'), '2' => __('Seq_flag 2')];
    }


    public function getChangeTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['change_type']) ? $data['change_type'] : '');
        $list = $this->getChangeTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSeqFlagTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['seq_flag']) ? $data['seq_flag'] : '');
        $list = $this->getSeqFlagList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getChangeTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['change_time']) ? $data['change_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setChangeTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
